<%@include file="/WEB-INF/header.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<div id="page-wrapper">
	<!-- 模态框（Modal） -->
	<form
		action="${pageContext.request.contextPath }/score/addScore.action"
		class="form-horizontal" role="form">
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="myModalLabel">发布新成绩</h4>
					</div>
					<div class="modal-body">
						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">班级</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="student_class"
									id="" placeholder="请输入班级" required="required">
							</div>
						</div>
						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">学号</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="student_id" id=""
									placeholder="请输入学号" required="required">
							</div>
						</div>
						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">姓名</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="student_name"
									id="" placeholder="请输入教师用户名" required="required">
							</div>
						</div>
						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">教师编号</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="teacher_id" id=""
									placeholder="请输入教师用户名" required="required">
							</div>
						</div>
						<div class="form-group">
							<label for="lastname" class="col-sm-2 control-label">课程名</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="c_name" id=""
									placeholder="请输入课程名" required="required">
							</div>
						</div>
						<!-- 						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">分数</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="score" id=""
									placeholder="请输入分数">
							</div>
						</div> -->

					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="submit" class="btn btn-primary">提交</button>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal -->
		</div>
	</form>
	<table class="table table-striped">
		<caption>
			<!-- 按钮触发模态框 -->
			<div class="col-md-3 data1">
				<c:if
					test="${sessionScope.USER_SESSION.user_rank == 1 ||  sessionScope.USER_SESSION.user_rank == 2}">
					<button class="btn btn-primary btn-sm" data-toggle="modal"
						data-target="#myModal">发布新成绩</button>
				</c:if>
				<br />
			</div>
			<br />
			<form action="${pageContext.request.contextPath}/score/findAll.action"
				method="post" class="form-horizontal" role="form">
				<div class="col-md-3 data1">
					<input type="text" class="form-control" name="data"
						placeholder="请输入查询内容" value="">
				</div>
				<button type="submit" class="btn bg-maroon">搜索</button>
			</form>
		</caption>
		<thead>
			<tr>
				<th>序号</th>
				<th>班级</th>
				<th>学号</th>
				<th>姓名</th>
				<c:if test="${sessionScope.USER_SESSION.user_rank != 5}">
				<th>专业教师用户名</th>
				</c:if>
				<th>课程名</th>
				<th>分数</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${scorelist}" var="l" varStatus="num">
				<c:if
					test="${sessionScope.USER_SESSION.user_name ==  l.teacher_id || sessionScope.USER_SESSION.user_rank == 1 || sessionScope.USER_SESSION.user_rank == 2 || sessionScope.USER_SESSION.user_rank == 3 || sessionScope.USER_SESSION.user_name == l.student_id}">
					<tr>
						<td>${num.index+1}</td>
						<td>${l.student_class}</td>
						<td>${l.student_id}</td>
						<td>${l.student_name}</td>
						<c:if test="${sessionScope.USER_SESSION.user_rank != 5}">
						<td>${l.teacher_id}</td>
						</c:if>
						<td>${l.c_name}</td>
						<c:if test="${l.score != null && sessionScope.USER_SESSION.user_rank != 2}">
						<td>${l.score}</td>
						</c:if>
						<c:if test="${l.score != null && sessionScope.USER_SESSION.user_rank == 2}">
						<td>完成</td>
						</c:if>
						<c:if test="${l.score == null}">
						<td>等待录入</td>
						</c:if>
						<c:if test="${sessionScope.USER_SESSION.user_rank == 1 || sessionScope.USER_SESSION.user_rank == 2}">
							<td><a href="#" class="btn btn-info btn-xs"
								data-toggle="modal" data-target="#goodEditDialog" role="button"
								onclick="returnInfor(${l.id})">修改</a> <a
								href="${pageContext.request.contextPath }/score/delScore.action?scoreid=${l.id}"
								onclick="javascript:return confirm('确实要删除该班级吗?')"
								class="btn btn-danger btn-xs" role="button">删除</a></td>
						</c:if>
						<c:if test="${sessionScope.USER_SESSION.user_rank == 4  && l.score == null}">
							<td><a href="#" class="btn btn-info btn-xs"
								data-toggle="modal" data-target="#modal2" role="button"
								onclick="returnInfor2(${l.id})">录入成绩</a></td>
						</c:if>
						<c:if test="${sessionScope.USER_SESSION.user_rank == 4}">
							<td><a href="#" class="btn btn-info btn-xs"
								data-toggle="modal" data-target="#modal2" role="button"
								onclick="returnInfor2(${l.id})">修改成绩</a></td>
						</c:if>
						<c:if
							test="${sessionScope.USER_SESSION.user_rank == 3 ||  sessionScope.USER_SESSION.user_rank == 5}">
							<td>不可操作</td>
						</c:if>
					</tr>
				</c:if>
			</c:forEach>
			<div class="modal fade" id="goodEditDialog" tabindex="-1"
				role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal"
								aria-hidden="true">&times;</button>
							<h4 class="modal-title" id="myModalLabel">修改成绩</h4>
						</div>
						<div class="modal-body">
							<form id="edit_user_form">
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">序号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="id" id="id"
											readonly>
									</div>
								</div>
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">班级</label>
									<div class="col-sm-10" >
										<input type="text" class="form-control" name="student_class"
											id="student_class" required="required">
									</div>
								</div>
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">学号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="student_id"
											id="student_id" placeholder="请输入学号" required="required">
									</div>
								</div>
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">姓名</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="student_name"
											id="student_name" placeholder="请输入姓名" required="required">
									</div>
								</div>
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">教师编号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="teacher_id"
											id="teacher_id" placeholder="请输入教师用户名" required="required">
									</div>
								</div>
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">课程名</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="c_name"
											id="c_name" placeholder="请输入课程名" required="required">
									</div>
								</div>

								<!-- 								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">分数</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="score"
											id="score" placeholder="请打分">
									</div>
								</div> -->
							</form>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default"
								data-dismiss="modal">关闭</button>
							<button type="submit" class="btn btn-primary"
								onclick="updateScore()">提交</button>
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal -->
			</div>
			<div class="modal fade" id="modal2" tabindex="-1" role="dialog"
				aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-body">
							<form id="edit_user_form2">
								<div class="form-group" hidden>
									<label for="firstname" class="col-sm-2 control-label">序号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="id" id="id2">
									</div>
								</div>
								<div class="form-group" hidden>
									<label for="firstname" class="col-sm-2 control-label">班级</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="student_class"
											id="student_class2">
									</div>
								</div>
								<div class="form-group" hidden>
									<label for="firstname" class="col-sm-2 control-label">学号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="student_id"
											id="student_id2" placeholder="请输入学号">
									</div>
								</div>
								<div class="form-group" hidden>
									<label for="firstname" class="col-sm-2 control-label">姓名</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="student_name"
											id="student_name2" placeholder="请输入姓名">
									</div>
								</div>
								<div class="form-group" hidden>
									<label for="firstname" class="col-sm-2 control-label">教师编号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="teacher_id"
											id="teacher_id2" placeholder="请输入教师用户名">
									</div>
								</div>
								<div class="form-group" hidden>
									<label for="firstname" class="col-sm-2 control-label">课程名</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="c_name"
											id="c_name2" placeholder="请输入课程名">
									</div>
								</div>
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">分数</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="score"
											id="score2" placeholder="请打分">
									</div>
								</div>
							</form>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default"
								data-dismiss="modal">关闭</button>
							<button type="submit" class="btn btn-primary" onclick="Score()">提交</button>
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal -->
			</div>

		</tbody>
	</table>
	<script type="text/javascript">
	// 通过id获取修改的商品信息
	  function returnInfor(id) {
			
			$.post("${pageContext.request.contextPath}/score/getscoreId.action",{"id":id},function(data){
				$("#id").val(data.id);
				$("#student_class").val(data.student_class);
				$("#student_id").val(data.student_id);
				$("#student_name").val(data.student_name);
		         $("#teacher_id").val(data.teacher_id);
		         $("#c_name").val(data.c_name);
		         $("#score").val(data.score);
			});
		}
	  function returnInfor2(id) {
			
			$.post("${pageContext.request.contextPath}/score/getscoreId.action",{"id":id},function(data){
				$("#id2").val(data.id);
				$("#student_class2").val(data.student_class);
				$("#student_id2").val(data.student_id);
				$("#student_name2").val(data.student_name);
		         $("#teacher_id2").val(data.teacher_id);
		         $("#c_name2").val(data.c_name);
		         $("#score2").val(data.score);
			});
		}
	  function updateScore() {
	  	
			$.post("${pageContext.request.contextPath}/score/updateScore.action",$("#edit_user_form").serialize(),function(data){
				if(data =="OK"){
					alert("信息修改成功！");
					window.location.reload();
				}else{
					alert("信息修改失败！");
					window.location.reload();
				}
			});
		}
	  function Score() {
		  var inputEle = document.getElementById("score2").value;
		  if(inputEle >= 0 && inputEle <= 100){
			 $.post("${pageContext.request.contextPath}/score/updateScore.action",$("#edit_user_form2").serialize(),function(data){
				if(data =="OK"){
					alert("打分成功！");
					window.location.reload();
				}else{
					alert("打分失败！");
					window.location.reload();
				}
			}); 
		  }else{
			  alert("分数不合法！");
		  }
		  

		}
</script>
</div>
<%@include file="/WEB-INF/footer.jsp"%>